function PlotAssignments(agents, tasks)

%---------------------------------------------------------------------%
% Set plotting parameters

set(0, 'DefaultAxesFontSize', 12)
set(0, 'DefaultTextFontSize', 10, 'DefaultTextFontWeight','demi')
%set(0,'DefaultAxesFontName','宋体')
%set(0,'DefaultTextFontName','arial')
set(0,'DefaultLineLineWidth',2); % < == very important
set(0,'DefaultlineMarkerSize',10)

% %---------------------------------------------------------------------%
% % Plot agent and task positions vs. time
% 
offset = 1; 
%fig    = figure(figureID);
figure('Renderer', 'painters', 'Position', [100 100 700 550]); 
Cmap   = colormap('lines');

spots_number=length(tasks);
for i=1:spots_number
    spots(i,:)=tasks(i).x';
    spots_m(i,:)=tasks(i).m';
end
% Plot tasks @ start
for m=1:spots_number
    h=plot(spots(m,1) , spots(m,2) ,'x','Color', [100, 100, 100] / 255,'LineWidth',3);
    hold on
    plot(spots_m(m,1) , spots_m(m,2) ,'o','Color', [100, 100, 100] / 255,'LineWidth',3);
    plot([spots(m,1) spots_m(m,1)],[spots(m,2) spots_m(m,2)],'Color',[100, 100, 100] / 255,'LineStyle','--')
    text(spots_m(m,1)  +offset, spots_m(m,2) +offset, ['Task' num2str(tasks(m).id)]);
    hold on; 
end

for n=1:length(agents)
    plot3(agents(n).x(1), agents(n).x(2), 0,'o','color',Cmap(agents(n).id,:));
    text(agents(n).x(1)+offset, agents(n).x(2)+offset, 0.1, ['USV ' num2str(n)],'color',Cmap(agents(n).id,:),'FontSize',14);
    %path=origin_id(agents(n).p,agents(n).tasks); 
    path=agents(n).p;
    if ~isempty(agents(n).p)
        [taskn,~]=Task.find_by_id(agents(n).tasks, agents(n).p(1));
        %visitTime=norm(agents(n).x-taskn.x)/agents(n).v_max;
        %plot(taskn.x(1), taskn.x(2),':','Color', [100, 100, 100] / 255,'LineWidth',3);
        plot([agents(n).x(1), taskn.m(1)] , [agents(n).x(2), taskn.m(2)]  ,'-^','Color',Cmap(agents(n).id,:));
        %text(taskn.m(1)  +offset, taskn.m(2) +offset, ['Task' num2str(path(1))]);
        for m = 2:length(agents(n).p)
            pre_taskn=Task.find_by_id(agents(n).tasks, agents(n).p(m-1));
            next_taskn=Task.find_by_id(agents(n).tasks, agents(n).p(m));
            X=[pre_taskn.m(1) next_taskn.m(1)];Y=[pre_taskn.m(2) next_taskn.m(2)];
            plot(X,Y,'-^','color',Cmap(agents(n).id,:));
            %text(next_taskn.m(1)  +offset, next_taskn.m(2) +offset, ['Task' num2str(path(m))]);
        end
    end
end
% path_info=[]; %路径点，抵达时间，机器人id，执行任务量
% for n=1:length(agents)
%     pn=[];
%     for m=1:length(agents(n).p)
%         pn=[pn,agents(n).p(m)];
%         dis_info(1)=agents(n).p(m);
% %         if agents(n).p(m)>100
% %             dis_info(1)=origin_id(agents(n).p(m), agents(n).tasks);
% %         else
% %             dis_info(1)=agents(n).p(m);
% %         end
%         dis_info(2) = agents(n).tj(pn);agents(n).times(m)=agents(n).tj(pn)-agents(n).dur_time;
%         dis_info(3)=n;dis_info(4)=agents(n).b_num(m);
%         path_info=[path_info; dis_info];
%     end
% end
t_score=0;
for i=1:length(agents)
    t_score=t_score+agents(i).sp;
end

hold off;
title(['分布式救援路线图(总时间满意度：' ,num2str(t_score),')'],'FontSize',16)
xlabel('X/m','FontSize',14);
ylabel('Y/m','FontSize',14);
grid on

% Plot agent schedules
simDurWks=0;
Cmap   = colormap('lines');
%fig = figure(figureID+1);
figure('Renderer', 'painters', 'Position', [100 100 700 550]); 
subplot(length(agents),1,1);
title(['双体无人艇执行计划'],'FontSize',16)


for n=1:length(agents)
    subplot(length(agents),1,n);
    ylabel(['USV ' num2str(n)],'FontSize',14,'FontWeight','bold')
    hold on;
    grid on;
%    axis([0 simDurWks, 0 2])
    
    for m = 1:length(agents(n).p)
        if (agents(n).p > -1)
            plot([agents(n).times(m) agents(n).times(m)+agents(n).dur_time],[1 1],'-','color',Cmap(agents(n).id,:), 'Linewidth',10)
            if mod(m,2)==1
               t = text(agents(n).times(m)-3, 1-0.3, ['Task' num2str(agents(n).p(m))]);
            else
               t = text(agents(n).times(m)-3, 1+0.3, ['Task' num2str(agents(n).p(m))]);
            end
            %s = t.FontSize;
            %t.FontSize = 12;
            t.FontWeight = 'bold';
            if m>1    
                plot([agents(n).times(m-1)+agents(n).dur_time agents(n).times(m)],[1 1],'--','color',Cmap(agents(n).id,:))
            else
                plot([0 agents(n).times(m)],[1 1],'--','color',Cmap(agents(n).id,:))
            end
        else
            break;
        end
    end
    ax=gca;
    if simDurWks<ax.XLim(end)
        simDurWks=ax.XLim(end);
    end
end
xlabel('时间/s','FontSize',14);
for n=1:length(agents)
    subplot(length(agents),1,n);
    axis([0 simDurWks, 0 2])
end

total_path_time=0;total_path_long=0;
for i=1:length(agents)
    total_path_time=total_path_time+agents(i).times(end)+agents(i).dur_time;
    total_path_long=total_path_long+agents(i).t_p(agents(i).p);
end

fprintf('\t total path_time: %d', total_path_time);
fprintf('\n');
fprintf('\t total path_long: %d', total_path_long);
fprintf('\n');
legend(h,'落水者初始位置')
end
